import React from 'react';
import { ts2Formatter,renderState,renderEnable } from 'utils';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询部门片区  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "organizationId",
        codename: "organizationCode",
        showname: "organizationName",
        zhname: "销售组织",
        edit: true,
        size:"md",
        param:{
            "AUTH_refdim":"organization","AUTH_refcod":"StrategyExtMatch"
        },
        cascadeName: [{
            paramkey: "EQ_organization",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "strategyId",
            resetOffersFlag: true,
        },{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "departmentId",
            resetOffersFlag: true,
        }],
        cascadeChildTable:[{
            refKey: "refpk", 
            dtoKey: "organizationId",
            childType:"strategyMatchExtCusts" 
        }],
        type: "RefComponent",
        refname: "organization",
    },
    {
        enname: "priceBillTypeId",
        codename: "priceBillTypeCode",
        showname: "priceBillTypeName",
        zhname: "单据类型",
        type: "Select",
        code:"BILL_TYPE_PRICE",
        showcontrol:[
            {
                value: "02",
                refKey: "code",
                dtoKey: "priceBillTypeCode",
                layer: ["childTableColumn", "strategyMatchItems", "column"],
                fields: ["goodsName", "goodsPrice"]
            },{
                value: "01",
                refKey: "code",
                dtoKey: "priceBillTypeCode",
                layer: ["childTableColumn", "strategyMatchItems", "column"],
                fields: ["brandName", "categoryName"]
            },
            {
                value: "01,02",
                refKey: "code",
                dtoKey: "priceBillTypeCode",
                layer: ["childTableColumn", "strategyMatchItems", "column"],
                fields: ["discountRate"]
            },
            {
                value: "02,03",
                refKey: "code",
                dtoKey: "priceBillTypeCode",
                layer: ["childTableColumn", "strategyMatchItems", "column"],
                fields: ["goodsName"]
            },
            {
                value: "03",
                refKey: "code",
                dtoKey: "priceBillTypeCode",
                layer: ["childTableColumn", "strategyMatchItems", "column"],
                fields: ["proposalRetailPrice", "proposalDealPrice"]
            }],
        edit: true,
        required: true,
    },
    {
        enname: "billStatusId",
        codename: "billStatusCode",
        showname: "billStatusName",
        zhname: "单据状态", 
        type: "Select",
        code:"BILL_STATUS",
        hidepage:{0:true},
        edit: false,
    },
    {
        enname: "priceSetDimensionId",
        codename: "priceSetDimensionCode",
        showname: "priceSetDimensionName",
        zhname: "设置维度", 
        type: "Select",
        code:"PRICE_SET_DIMENSION",
        // hidepage:{0:true},
        required:true,
        showcontrol: [{
            value: "01",
            refKey: "code",
            dtoKey: "priceSetDimensionCode",
            layer: ["childTableColumn", "strategyMatchExtCusts"],
            fields: "all"
        },{
            value: "02",
            refKey: "code",
            dtoKey: "priceSetDimensionCode",
            layer: ["childTableColumn", "channelAndDepartment","column"],
            fields: ["departmentName"]
        },{
            value: "02,03",
            refKey: "code",
            dtoKey: "priceSetDimensionCode",
            layer: ["childTableColumn", "channelAndDepartment","column"],
            fields: ["channelTypeName"]
        }],
        edit: true,
    },
    {
        enname: "strategyId",
        codename: "strategyCode",
        showname: "strategyName",
        zhname: "定价策略",
        type: "RefComponent",
        alias: "organizationId",
        refname:"priceStrategys",
        relation: [
            {
                ref: "priceListItemId1",
                refpk: "priceListItemId1",
                refcode: "priceListItemCode1",
                refname: "priceListItemName1",
                relationType: "ref",
        },
        {
            ref: "priceListItemId2",
            refpk: "priceListItemId2",
            refcode: "priceListItemCode2",
            refname: "priceListItemName2",
            relationType: "ref",
        }],

        edit: true,
        required:true,
    }, 
    {
        enname: "priceListItemId1",
        codename: "priceListItemCode1",
        showname: "priceListItemName1",
        zhname: "考核成本",
        edit: false,
        // hidepage:{0:true},
        type: "RefComponent",
        refname:"priceList",
        required: false,
    },
    {
        enname: "priceListItemId2",
        codename: "priceListItemCode2",
        showname: "priceListItemName2",
        zhname: "参考供价",
        edit: false,
        // hidepage:{0:true},
        type: "RefComponent",
        refname:"priceList",
        required: false,
    },
    {
        enname: "machineStatusId",
        codename: "machineStatusCode",
        showname: "machineStatusName",
        // zhname: "机器状态",
        zhname: "商品类型",
        edit: true,
        type: "RefComponent",
        refname:"machineRef",
        required: true,
    },
    // {
    //     enname: "customerId",
    //     codename: "customerCode",
    //     showname: "customerName",
    //     zhname: "客户",
    //     edit: true,
    //     type: "RefComponent",
    //     refname:"terminalcustomerRef",
    //     required: false,
    // },
    {
        enname: "billCode",
        zhname: "单据号",
        edit: false,
        hidepage:{0:true},
        type: "FormControl",
        required: false,
    },
    {
        enname: "startDate",
        zhname: "开始日期",
        edit: true,
        type: "DatePicker",
        format:"YYYY-MM-DD",
        required: true,
    },
    {
        enname: "endDate",
        zhname: "截止日期",
        edit: true,
        type: "DatePicker",
        disabledDate:"startDate",
        format:"YYYY-MM-DD",
        required: true,
    },
    {
        enname: "billMakerId",
        codename: "billMakerCode",
        showname: "billMakerName",
        zhname: "制单人",
        edit: false,
        hidepage:{0:true},
        type: "RefComponent",
        refname:"personRef",
        required: false,
    },
    {
        enname: "approveTime",
        zhname: "审批日期",
        edit: true,
        type: "DatePicker",
        format:"YYYY-MM-DD",
        hidepage:{0:true},
        required: false,
    },
    {
        enname: "creationTime",
        zhname: "制单日期",
        edit: true,
        type: "DatePicker",
        format:"YYYY-MM-DD hh:mm:ss",
        hidepage:{0:true},
        required: false,
    },
    {
        enname: "modifier",
        zhname: "修改人",
        edit: true,
        type: "FormControl",
        hidepage:{0:true},
        required: false,
    },
    {
        enname: "modifiedTime",
        zhname: "修改日期",
        edit: true,
        type: "DatePicker",
        format:"YYYY-MM-DD hh:mm:ss",
        hidepage:{0:true},
        required: false,
    },
    {
        enname: "remark",
        zhname: "备注",
        edit: true,
        type: "FormControl",
        componentClass: "textarea",
        pattern:/^\S*$/,
        message: "不能有空格",
        required: false,
    },
];

const columnstrategyMatchExtCusts = [
    {
        title: "客户",
        dataIndex: "customerName",
        key: "customerId",
        renderType: "refcomponent",
        width: 250,
        hideFlag:true,
        required:true,
        validate:false,
        filedProps: {
            title: "客户",
            multiple:true,
            refName: "terminalcustomerRef",
            constparam:{
                "AUTH_refdim": "customer", 
                "AUTH_refcod": "StrategyExtMatch",
                "EQ_isFrozen": "0"
            },
            aliasparam: [{
                paramkey: "EQ_customerAreas.organization.id",
                alias: "organizationId",
            }],
            offersparam: {
                currentkey: ["custChanTypeId","custChanTypeName","custChanTypeCode"],
                offerfields: ["channelTypeId","channelTypeName","channelTypeCode"],
            },
            fieldName: "customerName",
            reffields: { refpk: "customerId", refname: "customerName", refcode: "customerCode" }
        },
    },
]

const columnchannelAndDepartment = [
    {
        title: "渠道",
        dataIndex: "channelTypeName",
        key: "channelTypeId",
        renderType: "refcomponent",
        width: 250,
        hideFlag:true,
        required:true,
        validate:false,
        filedProps: {
            title: "渠道",
            refName: "custchantype1",
            fieldName: "channelTypeName",
            reffields: { refpk: "channelTypeId", refname: "channelTypeName", refcode: "channelTypeCode" }
        },
    },
    {
        title: "部门",
        dataIndex: "departmentName",
        key: "departmentId",
        renderType: "refcomponent",
        width: 250,
        hideFlag:true,
        required:true,
        validate:false,
        filedProps: {
            title: "渠道",
            refName: "departmentRef",
            fieldName: "departmentName",
            reffields: { refpk: "departmentId", refname: "departmentName", refcode: "departmentCode" }
        },
    },
]

const columnstrategyMatchItems = [
    {
        title: "商品",
        dataIndex: "goodsName",
        key: "goodsId",
        renderType: "refcomponent",
        width: 200,
        validate: false,
        required:true,
        filedProps: {
            title: "商品",
            refName: "goodsRef",
            fieldName: "goodsName",
            offersparam: {
                currentkey: ["ext07Id", "ext07Code", "ext07Name","brandId", "brandCode", "brandName"],
                offerfields: ["categoryId", "categoryCode", "categoryName","brandId", "brandCode", "brandName"],
            },
            reffields: { refpk: "goodsId", refname: "goodsName", refcode: "goodsCode" }
        },
    },
    {
        title: "品牌",
        dataIndex: "brandName",
        key: "brandId",
        renderType: "refcomponent",
        required:true,
        validate:false,
        width: 250,
        filedProps: {
            title: "品牌",
            refName: "brandref",
            fieldName: "brandName",
            reffields: { refpk: "brandId", refname: "brandName", refcode: "brandCode" }
        },
    },
    {
        title: "品类",
        dataIndex: "categoryName",
        key: "categoryId",
        renderType: "refcomponent",
        width: 250,
        required:true,
        validate:false,
        filedProps: {
            title: "品类",
            refName: "terminalGoodsCate",
            fieldName: "ext07Name",
            reffields: { refpk: "categoryId", refname: "categoryName", refcode: "categoryCode" }
        },
    },
    
    {
        title: "月返%",
        dataIndex: "discountRate",
        key: "discountRate",
        width: 110,
        validate: false,
        required: true,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
            max:100
        }
    },
    {
        title: "商品价格",
        dataIndex: "goodsPrice",
        key: "goodsPrice",
        width: 110,
        renderType: "inputnumber",
        required:true,
        validate:false,
        filedProps: {
            precision: 2,
            except:0,
            min: 0,
        }
    },
    {
        title: "子公司建议零售价",
        dataIndex: "proposalRetailPrice",
        key: "proposalRetailPrice",
        width: 140,
        renderType: "inputnumber",
        required:true,
        validate:false,
        filedProps: {
            precision: 2,
            except:0,
            min: 0,
        }
    },
    {
        title: "子公司建议成交价",
        dataIndex: "proposalDealPrice",
        key: "proposalDealPrice",
        width: 120,
        renderType: "inputnumber",
        required:true,
        validate:false,
        filedProps: {
            precision: 2,
            except:0,
            min: 0,
        }
    },
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}


const columnexpenseSummaryAttachments = [
    {
        title: "标题",
        dataIndex: "filename",
        key: "filename",
        width: 150,
    }, {
        title: "上传时间",
        dataIndex: "creationTime",
        key: "creationTime",
        width: 150,
        render: (text, record, index) => {
            return text && ts2Formatter(text);
        }
    }, {
        title: "缩略图",
        dataIndex: "fileUrl",
        key: "fileUrl",
        width: 150,
        render: (text, record, index) => {
            if(record.fileUrl.search("jpg") != -1 || record.fileUrl.search("jpeg") != -1 ||record.fileUrl.search("png") != -1){
                return <span>
                <img style={{"width":"35px"}} src={text} />
             </span>
            }else {
                return ""
            }
            
        }
    }, 
    {
        title: "创建人",
        dataIndex: "creator",
        key: "creator",
        width: 150,
    }
]
//渲染成字表表格的头
export const childTableColumn = {
    "strategyMatchItems": {
        "title": "明细",
        "type": "grid",
        "column": columnstrategyMatchItems
    },
    "strategyMatchExtCusts": {
        "title": "客户明细",
        "type": "grid",
        "column": columnstrategyMatchExtCusts
    },
    "channelAndDepartment": {
        "title": "部门渠道",
        "type": "grid",
        "column": columnchannelAndDepartment
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "billCode",
        key: "billCode",
        width:140,
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'StrategyExtMatch-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "销售组织",
        dataIndex: "organizationName",
        width: 160,
        key: "organizationName",
    },
    {
        title: "单据类型",
        dataIndex: "priceBillTypeName",
        width: 100,
        key: "priceBillTypeName",
    },
    {
        title: "单据状态",
        dataIndex: "state",
        key: "state",
        width: 100,
        render:(text) => {
            return renderState(text);
        }
    },
    {
        title: "定价策略ID",
        dataIndex: "strategyName",
        width:90,
        key: "strategyName",
    },
    {
        title: "考核成本",
        dataIndex: "priceListItemName1",
        key: "priceListItemName1",
        width:110,
    },
    {
        title: "建议供价",
        dataIndex: "priceListItemName2",
        key: "priceListItemName2",
        width:110,
    },
    // {
    //     title: "渠道",
    //     dataIndex: "channelTypeName",
    //     width: 110,
    //     key: "channelTypeName",
    // },
    // {
    //     title: "部门片区",
    //     dataIndex: "departmentName",
    //     width: 120,
    //     key: "departmentName",
    // },
    {
        // title: "机器状态",
        title: "商品类型",
        dataIndex: "machineStatusName",
        width: 120,
        key: "machineStatusName",
    },
    // {
    //     title: "客户",
    //     dataIndex: "customerName",
    //     width: 120,
    //     key: "customerName",
    // },
    {
        title: "单据号",
        dataIndex: "billCode",
        width: 120,
        key: "billCode",
    },
    {
        title: "备注",
        dataIndex: "remark",
        width: 120,
        key: "remark",
    },
    {
        title: "开始日期",
        dataIndex: "startDate",
        width: 120,
        key: "startDate",
        render:(text) => {
            return text && ts2Formatter(text);
        }
    },
    {
        title: "截止日期",
        dataIndex: "endDate",
        width: 120,
        key: "endDate",
        render:(text) => {
            return text && ts2Formatter(text);
        }
    }
]
export const searchField = [
    {
        enname: "organization",
        zhname: "销售组织",
        edit: true,
        type: "RefComponent",
        multiple:true,
        param:{
            "AUTH_refdim":"organization","AUTH_refcod":"StrategyExtMatch"
        },
        cascadeName: [{
                paramkey: "EQ_organization.id",
                childtype: "DataHeader",
                refKey: "refpk",
                dtoKey: "organization",
                offers: "channelAndDepartment&department",
                resetOffersFlag: true,
            },{
                paramkey: "EQ_organization",
                childtype: "DataHeader",
                refKey: "refpk",
                dtoKey: "organization",
                offers: "strategy",
                resetOffersFlag: true,
            },{
                paramkey: "EQ_customerAreas.organization.id",
                childtype: "DataHeader",
                refKey: "refpk",
                dtoKey: "organization",
                offers: "strategyMatchExtCusts&customer",
                resetOffersFlag: true,
            }
        ],
        refname: "organization",
        realRef:true,
    },
    {
        enname: "billCode",
        zhname: "单号",
        type: "FormControl",
        searchType:"like",
        edit: true,
    },
    {
        enname: "strategyMatchExtCusts&customer",
        zhname: "客户",
        refname:"terminalcustomerRef",
        type: "RefComponent",
        alias:"organization",
        realRef:true,
        multiple:true,
        edit: true,
    },
    {
        enname: "strategyMatchItems&goods",
        zhname: "商品",
        refname:"goodsRef",
        type: "RefComponent",
        multiple:true,
        realRef:true,
        edit: true,
    },
    {
        enname: "strategyMatchItems&category",
        zhname: "品类",
        refname:"terminalGoodsCate",
        type: "RefComponent",
        multiple:true,
        realRef:true,
        edit: true,
    },
    {
        enname: "strategyMatchItems&brand",
        zhname: "品牌",
        refname:"brandref",
        type: "RefComponent",
        multiple:true,
        realRef:true,
        edit: true,
    },
    {
        enname: "date",
        zhname: "有效性",
        type: "RangePicker",
        rangeField:["startDate","endDate"],
        edit: true,
    },
    {
        enname: "priceBillType",
        zhname: "单据类型",
        type: "Select",
        code:"BILL_TYPE_PRICE",
        edit: true,
    },
    {
        enname: "priceSetDimension",
        zhname: "设置维度",
        type: "Select",
        code:"PRICE_SET_DIMENSION",
        edit: true,
    },
    {
        enname: "state",
        zhname: "单据状态", 
        type: "Select",
        code:"BILL_STATUS",
        edit: true,
    },
    {
        enname: "strategy",
        zhname: "定价策略",
        type: "RefComponent",
        refname:"priceStrategys",
        param:{
            "EQ_organization":""
        },
        alias:"organization",
        multiple:true,
        edit: true,
        realRef:true,
    }, 
    {
        enname: "channelAndDepartment&channelType",
        zhname: "渠道",
        edit: true,
        type: "RefComponent",
        refname:"custchantype",
        param:{
            "EQ_enableState":"2"
        },
        multiple:true,
        required: false,
        realRef:true,
    },
    {
        enname: "channelAndDepartment&department",
        zhname: "部门片区",
        edit: true,
        type: "RefComponent",
        refname:"departmentRef",
        alias:"organization",
        multiple:true,
        required: false,
        realRef:true,
    },
    {
        enname: "machineStatus",
        realRef:true,
        // zhname: "机器状态",
        zhname: "商品类型",
        edit: true,
        type: "RefComponent",
        multiple:true,
        refname:"machineRef",
    },
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "001",
    }
    // {
    //     event: "ButtonEnable",
    //     zhname: "启用",
    //     authcode: "Summarystart",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-price/price/strategy-match-ext/enable'
    // },
    // {
    //     event: "ButtonEnable",
    //     zhname: "停用",
    //     authcode: "Summarystop",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-price/price/strategy-match-ext/disenable'
    // }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-price/price/strategy-match-ext/deleteByIds'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["BILL_STATUS","BILL_TYPE_PRICE","PRICE_SET_DIMENSION"]
